var SUCCESS = "success";
var ERROR = "danger";
var INFO = "info";

function showMessage(type, id, msg) {
	var code = "<div class=\"alert alert-"
			+ type
			+ "\">"
			+ "<button type=\"button\" class=\"close\" data-dismiss=\"alert\">\&times;</button>";

	if (type == "success") {
		code += "<b>Success!</b>";
	} else if (type == "danger") {
		code += "<b>Error!</b>";
	}

	code += "&nbsp;&nbsp;<span>" + msg + "</span>" + "</div>";

	$("#" + id).html(code);
	setTimeout(function(){$('#'+id).html('')},10000);
}

function login(){
	var uname = $('#username').val();
	var pass = $('#password').val();
	
	if(uname == "")
	{
		showMessage(ERROR,"login_err_msg", "Please fill the username field.");
		$('#user-name').focus();
		return;
	}
	
	if(pass == "")
	{
		showMessage(ERROR,"login_err_msg", "Please fill the password field.");
		$('#user-password').focus();
		return;		
	}
	
	$.post("php/adminLogin.php",{
				name : uname,
				pass : pass
			},
		function(response){
			if(response.error == "false"){
				$('#username').val('');
				$('#password').val('');
				window.location.href = "masterpage.html"		
			}else{
				showMessage(ERROR,"login_err_msg", response.message);
			}
		},
	"json");

}
